{% from "macros/table.html" import table, table_decoration %}
{% from "macros/buttons.html" import import_button %}

{% set columns = columns | default([]) %}
{% set actions = actions | default([]) %}
{% set data = word_lists %}
{% set table_container = "word_list-table-container" %}

<div id="{{ table_container }}" class="table-container" x-data='{ selectedItems: [], exportUrl: "{{ url_for("admin.export_word_lists") }}" }'>
  {% call table_decoration(name, model_name, table_container, routes=routes) %}
    <div class="grow-0">
      <div class="join gap-1" hx-target="#form-container">
        <button hx-post="{{ url_for('admin.update_all_word_lists') }}" class="btn btn-outline">
          {{ heroicon_outline("arrows-pointing-in", class="h-5 w-5") }}
          Update Wordlists
        </button>
        {{ import_button(url_for('admin.import_word_lists') ) }}
        <a class="btn btn-outline btn-info"
           :href="exportUrl + (selectedItems.length > 0 ? '?' + selectedItems.map(id => 'ids=' + id).join('&') : '')"
           download>
          {{ heroicon_outline("document-arrow-down", class="h-5 w-5") }}
          Export
        </a>
      </div>
    </div>
  {% endcall %}
  {% if data and data | length > 0 %}
    {{ table(model_name + '-table', data, columns, actions=actions, standalone=false, routes=routes) }}
  {% else %}
    <div class="text-center p-4">
      <p class="text-gray-500">No {{ name }} available.</p>
      <button class="mt-2 btn btn-primary" hx-post="{{ url_for('admin.load_default_word_lists') }}" hx-target="#{{ table_container }}">
        Load default {{ name }}
      </button>
    </div>
  {% endif %}
</div>
